<?php

namespace app\site\service\delivery;

use app\model\delivery\PostageTemplate;
use app\model\delivery\PostageTemplateRegion;
use app\site\service\traits\InstanceTrait;
use think\db\Query;
use think\facade\Cache;

class PostageTemplateRegionService extends \app\site\service\SiteBaseService
{

    use InstanceTrait;

    function initialize()
    {
        $this->model = new PostageTemplateRegion();
    }

    function formatData(array $data): array
    {
        $data['region_ids'] = miImplode($data['regionIdArr']??'');
        unset($data['regionIdArr']);
        $data['region_info'] = serialize($data['regionInfoArr']??'');
        unset($data['regionInfoArr']);
        return  $data;
    }

    public function query(): Query
    {
        return $this->makeQuery()->filter(function ($v) {
            $v->regionIdArr = miExplode($v->region_ids);
            $v->regionInfoArr = miUnserialize($v->region_info);
        });
    }


}
